
#pragma once

#ifdef _FAN_FAN_
#include "ClientSocket.h"
#include "UploadList.h"

class CDlgMain;
class CJSONMsg;
class CInformationDelegate : public IClientSocketDelegate
{
public:
	CInformationDelegate(CDlgMain *owner);
	~CInformationDelegate() override;

	//IClientSocketDelegate
	void ClientConnected(CClientSocket *socket) override;
	void ClientDisconnected(CClientSocket *socket) override;
	void DataRecved(CClientSocket *socket, byte * data, intptr_t dataLength) override;
	void DataSended(CClientSocket *socket, LPVOID context) override {}
	void ThreadStoped(CClientSocket *socket) override;
	void KeepAlive(CClientSocket *socket) override;

	void Start();
	bool Stop(bool isDestroy);
	bool IsRunning();
	__forceinline bool IsConnected(){ return m_bConnected; }
	void MaintanaceThread();
	void Restart();
	void ClearDcdResult();
	bool Send(CJSONMsg &msg);
	__forceinline bool SendNow(byte *data, intptr_t dataLength, LPVOID context = nullptr)
	{
		return m_cSock.SendNow(data, dataLength, context);
	}

	CUploadList m_uploadList;
protected:
	void ProcessMsg(CClientSocket *socket, CJSONMsg &msg);
	bool SendData();
	volatile unsigned int lgToken; TICK lgTokenTick;

	CDlgMain *m_pOwner;
	CClientSocket m_cSock;
	HANDLE hThread;
	bool m_bStopThread, m_bConnected, m_bIsRestart, m_dcdResultCleared;
};
#endif
